"""
    Run.py - Starts the mud server
    Copyright (C) 2009  Matthew Baldwin <secretagentcook@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
"""
"""
Starts the server.
"""
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor

import Core
import Player

class SendContent(Protocol):
    """ This class controls the connections to the mud.  A quick note about the
        function name conventions in this file.  Usually the convention is 'foo_bar'
        but the following three are camel humped because they are overwriting
        functions already defined in the Protocal Class. """

    def connectionMade(self):
        self.transport.write(self.factory.text)
        self.playerRef = Player.Player.set_sock_ref(self.transport)
        Player.Player.info['login_state'] = Core.Const.loggin_in
        
    def dataReceived(self, data):
        data = data.strip('\r')
        data = data.strip('\n')
        #self.playerRef = Player.Player.get_sock_ref()
        Core.Handler.input_handler(data)

    def connectionLost(self, reason):
        pass

class SendContentFactory(Factory):
    protocol = SendContent
    def __init__(self, text=None):
        if text is None:
            text = """Hello.  Please state your name:  """
        self.text = text


reactor.listenTCP(Core.Const.port, SendContentFactory())
print 'Starting Server'
reactor.run()

